Code chaos

Het model van Lorenz

terug

/*from H Lauwerier Een wereld van fractals, Bloemendaal 1990
program Lorenz1 translated into Processing by J.G.van Unnik, 2012*/
//parameters
float angle=1.4;
import processing.opengl.*;
void setup(){
size(400,300,OPENGL);
stroke(0);
smooth();
noFill();
frameRate(10);
}

void draw(){
float a=10,b=8/3,c=28,d=.01,x=-12.5,y=-17.4,z=26;
float x1,x2,y1,y2,z1,z2;
background(255);
translate(200,275);
rotateX(1.5);
angle=angle+.02;
rotateZ(angle);
beginShape();
for(int m=1;m<2000;m++){
vertex(5*x,5*y,5*z); //draw point
x1=x+d*a*(y-x);
y1=y+d*(x*(c-z)-y);
z1=z+d*(x*y-b*z);
x2=x1+d*a*(y1-x1);
y2=y1+d*(x1*(c-z1)-y1);
z2=z1+d*(x1*y1-b*z1);
x=(x+x2)/2;
y=(y+y2)/2;
z=(z+z2)/2;
}
endShape();
}

Het model van Hénon

terug

//parameters
float a=.24, b=sqrt(1-sq(a));
//variables
float x,y,z;int t=0;
//define an array of 16 colour numbers
int[] colour={color(0,0,0),color(0,0,100),color(0,0,200),
color(0,0,255),color(100,0,255),color(200,0,255),color(255,0,255),color(255,0,200),color(255,0,100),

color(255,0,0),color(255,100,0),color(255,200,0),color(255,255,0),color(255,255,100),

color(255,255,200),color(255,255,255)};
void setup() {
size(300,300);
background(0);
}
void draw(){
x=-1+2*random(1);
y=-1+2*random(1);
int col=1+int(random(15));
for(int n=1;n<1000;n++){
if(abs(x)<1.5 && abs(y)<1.5){
int X=int(100*x+120),Y=int(100*y+150);    //scaling of X,Y-coordinates
set(X,Y,colour[col]);}
z=x;
x=x*a-(y-sq(x))*b;
y=z*b+(y-sq(z))*a;
if (abs(x)+abs(y)>10){n=1000;}  //'exit for-loop' condition
}
}
void mousePressed(){    //press a key to freeze or restart
t=t+1;
if (t%2==1){noLoop();}
else{loop();}
}

terug

Het model van Mira

/*from H.A. Lauwerier Graphics&Fractals, 1994 chapter 6  MIRADSX1 translated into
Processing by J.G.van Unnik, 2010*/
color lblue=color(0,255,255),lgreen=color(50,205,50),dgreen=color(0,100,0);
color dblue=color(0,0,128), sbrown=color(139,69,19),dorange=color(255,140,0);
color yellow=color(255,255,0);

float a=.3,k=2;
float x1=7,y1=0;int p1=2;
float x2=-12,y2=0;int p2=2;
float x3=-21,y3=0;int p3=2;
float x4=-21,y4=0;int p4=0;
float x5=-21,y5=0;int p5=0;
float x6=0,y6=0;int p6=0;
float x7=0,y7=0;int p7=0;

void setup(){
size(400,400);
background(0);
stroke(255);
noLoop();
}
void draw(){
translate(200,200);
stroke(lblue);
float x=x1,y=y1;int p=p1;
orbit(x,y,p);
stroke(dblue);
x=x2;y=y2;p=p2;
orbit(x,y,p);
stroke(lgreen);
x=x3;y=y3;p=p3;
orbit(x,y,p);
stroke(sbrown);
x=x4;y=y4;p=p4;
orbit(x,y,p);
stroke(dorange);
x=x5;y=y5;p=p5;
orbit(x,y,p);
stroke(yellow);
x=x6;y=y6;p=p6;
orbit(x,y,p);
stroke(255,255,255);
x=x7;y=y7;p=p7;
orbit(x,y,p);
}
void orbit(float x,float y,int p){
float c=2-2*a;
int kmax=1000*p;
float w=a*x+c*x*x/(1+x*x);
for(int k=0;k<kmax;k++){
point(8*x,8*y);
float z=x;
x=y+w;
float u=x*x;
w=a*x+c*u/(1+u);
y=w-z;
}
}
void mousePressed(){
k=k+1;
int rem=int(k%3);
switch(rem){
case 0:
a=.18;
x1=8;y1=0;p1=2;
x2=20;y2=0;p2=2;
x3=15;y3=0;p3=6;
x4=5.3;y4=0;p4=2;
x5=9;y5=0;p5=2;
x6=0;y6=0;p6=0;
x7=0;y7=0;p7=0;
break;
case 1:
a=-.05;
x1=9.8;y1=0;p1=1;
x2=20;y2=0;p2=4;
x3=15;y3=0;p3=2;
x2=2;y4=0;p4=4;
x5=18;y5=0;p5=2;
x6=25;y6=0;p6=6;
x7=7.5;y7=0;p7=4;
break;
default:
a=.3;
x1=7;y1=0;p1=2;
x2=-12;y2=0;p2=2;
x3=-21;y3=0;p3=2;
x4=-21;y4=0;p4=0;
x5=-21;y5=0;p5=0;
x6=0;y6=0;p6=0;
x7=0;y7=0;p7=0;
break;
}
background(0);
redraw();